package com.sgb.zhaocai.view.demand.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.sgb.zhaocai.BR;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.entity.DemandIssueListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;
import java.util.List;

/**
 * Time:2021/9/17
 * AUTHOR:F_Q
 * Description:
 */
public class DemandIssueAdapter extends BaseRecycleAdapter<DemandIssueListEntity> {

    public DemandIssueAdapter(Context context, List<DemandIssueListEntity> datas) {
        super(context, R.layout.zc_demand_issue_items, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        TextView createTime = holder.itemView.findViewById(R.id.createTime);//创建时间
        TextView publicity = holder.itemView.findViewById(R.id.publicity);//公示
        TextView cancelpublicity = holder.itemView.findViewById(R.id.cancel_publicity);//取消公示
        TextView edit = holder.itemView.findViewById(R.id.edit);//编辑
        TextView details = holder.itemView.findViewById(R.id.details);//查看详情
        TextView typeName = holder.itemView.findViewById(R.id.typeName);//标签类型
        switch (datas.get(position).getType()){
            case "1":
                typeName.setText("机械租赁");
                break;
            case "2":
                typeName.setText("劳务用工");
                break;
            case "3":
                typeName.setText("材料采购");
                break;
            case "4":
                typeName.setText("分包计划");
                break;
            case "5":
                typeName.setText("设备租赁");
                break;
        }
        if (!TextUtils.isEmpty(datas.get(position).getCreated())) {
            createTime.setText(DateUtils.timestampTo13Date3(Long.valueOf(datas.get(position).getCreated())));
        } else {
            createTime.setText("");
        }
        publicity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.Publicity(datas.get(position));
            }
        });
        cancelpublicity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.CancelPublicity(datas.get(position));
            }
        });
        edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.Edit(datas.get(position));
            }
        });
        details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.Details(datas.get(position));
            }
        });

    }

    @Override
    public void convert(ItemViewHolder holder, DemandIssueListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ImageView state = holder.itemView.findViewById(R.id.state);//状态
        TextView publicity = holder.itemView.findViewById(R.id.publicity);//公示
        TextView cancelpublicity = holder.itemView.findViewById(R.id.cancel_publicity);//取消公示
        TextView edit = holder.itemView.findViewById(R.id.edit);//编辑
        TextView offer_num = holder.itemView.findViewById(R.id.offer_num);//报价家数
        //发布通过的数据
        switch (entity.getStatus()) {
            case "1"://公示中
                publicity.setVisibility(View.GONE);
                cancelpublicity.setVisibility(View.VISIBLE);
                edit.setVisibility(View.GONE);
                state.setBackground(context.getResources().getDrawable(R.mipmap.zc_gsz));
                offer_num.setText(entity.getOfferCount());
                break;
            case "2"://未公示
                publicity.setVisibility(View.VISIBLE);
                cancelpublicity.setVisibility(View.GONE);
                edit.setVisibility(View.VISIBLE);
                state.setBackground(context.getResources().getDrawable(R.mipmap.zc_wgs));
                offer_num.setText(entity.getOfferCount());
                break;
            case "3"://草稿
                publicity.setVisibility(View.GONE);
                cancelpublicity.setVisibility(View.GONE);
                edit.setVisibility(View.VISIBLE);
                state.setBackground(context.getResources().getDrawable(R.mipmap.zc_cg));
                offer_num.setText(entity.getOfferCount());
                break;
        }
    }
    private OnItemStateOperate OnItemStateOperate;

    public void setOnItemStateOperate(OnItemStateOperate onItemStateOperate) {
        OnItemStateOperate = onItemStateOperate;
    }

    public interface OnItemStateOperate {

        void Publicity(DemandIssueListEntity entity);

        void CancelPublicity(DemandIssueListEntity entity);

        void Edit(DemandIssueListEntity entity);

        void Details(DemandIssueListEntity entity);
    }
}
